// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Force Field Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 61 : TYPE_FORCEFIELD

// Function declarations
reserve function ForceField_DebugDraw
reserve function ForceField_DebugSpawn

// Static Values

// Tables

function ForceField_DebugDraw
	temp6 = object.inkEffect
	temp7 = object.alpha
	object.inkEffect = INK_ADD
	temp1 = oscillation
	temp1 <<= 2
	Sin(temp0, temp1)
	object.alpha = temp0
	object.alpha >>= 5
	object.alpha += 80
	DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
	DrawSpriteFX(4, FX_INK, object.xpos, object.ypos)
	object.alpha = temp0
	object.alpha >>= 5
	object.alpha += 144
	DrawSpriteFX(1, FX_INK, object.xpos, object.ypos)
	DrawSpriteFX(3, FX_INK, object.xpos, object.ypos)
	object.alpha = temp0
	object.alpha >>= 4
	object.alpha += 192
	DrawSpriteFX(2, FX_INK, object.xpos, object.ypos)
	object.alpha = temp7
	object.inkEffect = temp6
end function


function ForceField_DebugSpawn
	CreateTempObject(TypeName[Force Field], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 5
	object[tempObjectPos].inkEffect = INK_ADD
end function


event ObjectMain
	switch object.state
	case 0
		temp0 = object.xpos
		temp0 += 0x160000
		if object[0].xpos > temp0
			object.state = 1
			object.alpha = 0
		endif
		break
	case 2
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -8, -80, 8, 80, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	case 1
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -8, -80, 8, 80, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		object.alpha ++
		if object.alpha > 80
			object.state ++
		endif
		break
	endswitch
	DrawNumbers(0, 104, 50, object.xpos, 6, 8, 0)
end event


event ObjectDraw
	if object.state == 1
		DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
		DrawSpriteFX(4, FX_INK, object.xpos, object.ypos)
		DrawSpriteFX(1, FX_INK, object.xpos, object.ypos)
		DrawSpriteFX(3, FX_INK, object.xpos, object.ypos)
	endif
	if object.state == 2
		temp1 = oscillation
		temp1 <<= 2
		Sin(temp0, temp1)
		object.alpha = temp0
		object.alpha >>= 5
		object.alpha += 80
		DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
		DrawSpriteFX(4, FX_INK, object.xpos, object.ypos)
		object.alpha = temp0
		object.alpha >>= 5
		object.alpha += 144
		DrawSpriteFX(1, FX_INK, object.xpos, object.ypos)
		DrawSpriteFX(3, FX_INK, object.xpos, object.ypos)
		object.alpha = temp0
		object.alpha >>= 4
		object.alpha += 192
		DrawSpriteFX(2, FX_INK, object.xpos, object.ypos)
	endif
end event


event ObjectStartup
	LoadSpriteSheet("SBZ/Objects.gif")
	SpriteFrame(-8, -72, 2, 144, 382, 266)
	SpriteFrame(-6, -72, 3, 144, 384, 266)
	SpriteFrame(-3, -72, 6, 144, 387, 266)
	SpriteFrame(3, -72, 3, 144, 393, 266)
	SpriteFrame(6, -72, 2, 144, 396, 266)
	foreach (TypeName[Force Field], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 5
		object[arrayPos0].inkEffect = INK_ADD
	next
	SetTableValue(TypeName[Force Field], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(ForceField_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(ForceField_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
